home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jam src / ThingBlocks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-09  |  1.5 KB  |  69 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: ThingBlocks.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Wednesday, September 9, 1992, 21:29
  6.      Created: Monday, March 9, 1992, 23:01
  7.  
  8.      Copyright © 1992, Juri Munkki
  9. /*/
  10.  
  11. #include "ThingBlocks.h"
  12.  
  13. ThingBlock    NewThingBlock(long thingSize)
  14. {
  15.     ThingBlockHeader    tbh;
  16.     ThingBlock            theBlock;
  17.     
  18.     tbh.thingSize = thingSize;
  19.     tbh.clumpSize = thingSize * 8;
  20.     tbh.numItems = 0;
  21.     tbh.logicalSize = sizeof(ThingBlockHeader)-sizeof(char)*2;
  22.     tbh.physicalSize = tbh.logicalSize;
  23.     
  24.     theBlock = (ThingBlock)NewHandle(tbh.physicalSize);
  25.     BlockMove(&tbh,*theBlock,tbh.logicalSize);
  26.     
  27.     return    theBlock;
  28. }
  29.  
  30. int        EnlargeThing(ThingBlock tb, long sizeRequested)
  31. {
  32.     ThingBlockHeader    *tbp;
  33.     long                newsize;
  34.     
  35.     tbp = *tb;
  36.     if(sizeRequested+tbp->logicalSize > tbp->physicalSize)
  37.     {    SetHandleSize(tb, tbp->logicalSize+tbp->clumpSize+sizeRequested);
  38.         tbp = *tb;
  39.         newsize = GetHandleSize(tb);
  40.         if(tbp->physicalSize == newsize)
  41.             return -1;
  42.         else
  43.         {    tbp->physicalSize = newsize;
  44.         }
  45.     }
  46.     return noErr;
  47. }
  48.  
  49. void    AddThing(ThingBlock tb, void *theThing)
  50. {
  51.     if(EnlargeThing(tb,(*tb)->thingSize) == noErr)
  52.     {    BlockMove(theThing,((char *)*tb)+(*tb)->logicalSize,(*tb)->thingSize);
  53.         (*tb)->logicalSize += (*tb)->thingSize;
  54.         (*tb)->numItems++;
  55.     }
  56. }
  57.  
  58. void    DeleteWithSwap(ThingBlock tb, int index)
  59. {
  60.     (*tb)->logicalSize -= (*tb)->thingSize;
  61.     (*tb)->numItems--;
  62.  
  63.     if((*tb)->numItems != index)
  64.         BlockMove(    ((Ptr)(*tb))+(*tb)->thingSize*index,
  65.                     ((Ptr)(*tb))+(*tb)->logicalSize,
  66.                     (*tb)->thingSize);
  67. }
  68.  
  69.